home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 1.5 KB | 43 lines | [TEXT/GEOL] |
- Item forwarded by ALCABES to CPLUS.APPLE$
-
- Item 8289649 24-Dec-89 08:06
-
- From: MIKE.VILOT ObjectWare, Michael Vilot,PRT
-
- To: MADA.EUROPE MacApp Dev Assoc Europe, E Carrasco
-
- cc: CPLUS.DEV$ C++ Interest List--Developers
-
- Sub: Re: ?Overloading the new…
-
- Try this:
- Class TGraphicSegment { // a PointerObject
- private:
- long fSize
- long fAddress
- /* ... */
- public:
- void* operator new(size_t); // class-specific allocation
- void* operator new(size_t, void*); // at a specfic placement
- void operator delete(void*); // class-specific deallocation
- void operator delete(void*, size_t); // of an array of objects
- /* ... */
- };
- ... if you really have to overload the operators.
- >Objects and their fields have to be
- >places in a specific location in our heap (a big block allocated at the
- >beginning of the application). Each object knows its size, location, and other
- >properties.
- Note that you can use the placement syntax with the existing, global
- operators new & delete to achieve the effect of allocating at a specific
- location:
- // see p. 79 of the C++ Reference Manual
- static char buf[sizeof(X)];
- X* p = new(&buf) X(args);
- Also, note that the compiler knows the size of objects, and passes this size
- as the first parameter to operator new.
-
- Hope this helps,
- Mike
-
-